<template>


    <SearchTablePage :search-config="baseTableSearchModel" :table-config="baseTableModel" />

</template>

<script lang="tsx" setup>
defineOptions({
    name: 'StaffInfoPageData',   //全局别名
    title: '表格页',   //标题
});
import { useEnumList } from '~/src/utils/useEnumList';
// 接口
import StaffInfoApi from '/@/api/webPath/StaffInfoApi.ts';


import FORM_FIELD_TYPE from '/@/constants/FormFieldType';
import VDialog from '/@/utils/dialogUtil.ts'
import { useTemplateName } from '~/src/utils/useTemplateName';

const router = useRouter();
const baseTable = ref(null as any);
const baseTableSearch = ref(null as any);
const editRef = ref<any>(null);
const staffSexEnumList = useEnumList("SexType")
const staffSeparationStatusList = useEnumList("StaffStatus")
const exportXlsName = useTemplateName("template_type_4")
// 表格搜索初始化searchModel
const baseTableSearchModel = ref({
    columnCount: 4,
    expandLimit: 6,
    autoFit: true,
    tooltip: true,
    columnWidth: '320px',
    labelPosition: 'right',
    labelWidth: '100px',
    items: [ //搜索项初始化

        // {
        //             label: "id",
        //             field: "id",
        //             clearable: true,
        //             type: FORM_FIELD_TYPE.INPUT,

        //            placeholder:"请输入",

        //         },

        {
            label: "名称",
            field: "staffName",
            clearable: true,
            type: FORM_FIELD_TYPE.INPUT,

            placeholder: "请输入",

        },

        {
            label: "身份证",
            field: "staffIdentity",
            clearable: true,
            type: FORM_FIELD_TYPE.INPUT,

            placeholder: "请输入",

        },

        {
            label: "性别",
            field: "staffSex",
            clearable: true,
            type: FORM_FIELD_TYPE.SINGLE_LAYER_SELECT,
            // options:[
            //     {
            //         value: '0',
            //         label: "女"
            //     },
            //     {
            //         value: '1',
            //         label: "男"
            //     },
            //     {
            //         value: 2,
            //         label: "未知"
            //     }
            // ],
            options: staffSexEnumList,


            placeholder: "请输入",

        },

        {
            label: "出生日期",
            field: "staffBirthDate",
            clearable: true,
            type: FORM_FIELD_TYPE.DATE_RANGE,
            placeholder: "请输入",

            config: {
                props: {   //日期精度配置
                    type: "daterange",
                    startPlaceholder: "开始日期",
                    endPlaceholder: "结束日期",
                    format: "YYYY-MM-DD",
                }
            },
        },

        {
            label: "职位",
            field: "staffPosition",
            clearable: true,
            type: FORM_FIELD_TYPE.INPUT,

            placeholder: "请输入",

        },

        {
            label: "入职日期",
            field: "staffEntryDate",
            clearable: true,
            type: FORM_FIELD_TYPE.DATE,
            placeholder: "请输入",

            config: {
                props: {   //日期精度配置
                    type: "daterange",
                    startPlaceholder: "开始日期",
                    endPlaceholder: "结束日期",
                    format: "YYYY-MM-DD",
                }
            },
        },

        {
            label: "健康证号",
            field: "healthCertificateCode",
            clearable: true,
            type: FORM_FIELD_TYPE.INPUT,

            placeholder: "请输入",

        },

        {
            label: "健康证有效期",
            field: "healthCertificateDate",
            clearable: true,
            type: FORM_FIELD_TYPE.DATE_RANGE,
            placeholder: "请输入",

            config: {
                props: {   //日期精度配置
                    type: "daterange",
                    startPlaceholder: "开始日期",
                    endPlaceholder: "结束日期",
                    format: "YYYY-MM-DD",
                }
            },
        },

        // {
        //     label: "所属公司",
        //     field: "companyId",
        //     clearable: true,
        //     type: FORM_FIELD_TYPE.INPUT,

        //     placeholder: "请输入",

        // },

        // {
        //     label: "是否离职",
        //     field: "status",
        //     clearable: true,
        //     type: FORM_FIELD_TYPE.SINGLE_LAYER_SELECT,
        //         // options: [
        //         //     {
        //         //         value: '0',
        //         //         label: "在职"
        //         //     },
        //         //     {
        //         //         value: '1',
        //         //         label: "离职"
        //         //     }
        //         // ],
        //         options: staffSeparationStatusList,
        //     placeholder: "请输入",

        // },

        // {
        //             label: "排序",
        //             field: "sort",
        //             clearable: true,
        //             type: FORM_FIELD_TYPE.INPUT,

        //            placeholder:"请输入",

        //         },

        // {
        //     label: "创建时间",
        //     field: "create_time",
        //     clearable: true,
        //     type: FORM_FIELD_TYPE.DATE_RANGE,

        //     placeholder: "请输入",

        // },

    ],

    buttons: [    //功能区域


        {
            name: "新增",
            buttonClass: 'primary',
            width: 100,
            click: ({ row, handlers }) => {        // 点击回调事件方法钩子，  点击触发

                VDialog.open({
                    title: '新增',

                    content: { //内容初始形式
                        type: 'component', //text:"",预留文本
                        name: '/staffInfo/edit',
                        query: {},

                    },

                    callBack: (data: any) => {
                        handlers.refresh()
                    },
                    onClose: () => {
                        console.log("对话框已关闭");
                    },
                });

            },
        },
        {
            name: "导入",
            buttonClass: 'primary',
            width: 100,
            click: ({ row, handlers }) => {   //暴露的方法钩子
                //  CompanyInfoApi.pageDataXls( handlers.getRequestParams(),handlers.getXlsTitle())
                VDialog.open({
                    title: '数据导入',
                    content: { //内容初始形式
                        type: 'component', //text:"",预留文本
                        name: '/AttachmentUpload',
                        // query: { companyInfoId: row.id },
                    },
                    config: {
                        doUpload: StaffInfoApi.uploadExcel,
                        doBatchSave: StaffInfoApi.batchSave,
                        templateType: "company_template_type_4",
                        // tips: '注：请先点击“下载模版”按钮下载模版，按照模版填写数据，再进行导入。'
                    },
                    callBack: (data: any) => {
                        handlers.refresh()
                        console.log("refresh", handlers.refresh)
                        // handlers.refresh()
                        console.log("upload recived data:", data)
                    },
                    onClose: () => {
                        console.log("对话框已关闭");
                    },
                })
            }
        },
        // {
        //     name: "导出",
        //     buttonClass: 'primary',
        //     width: 100,
        //     click: ({ row, handlers }) => {   //暴露的方法钩子
        //         StaffInfoApi.pageDataXls(handlers.getRequestParams(), handlers.getXlsTitle(), exportXlsName.value)
        //     }
        // },
        {
            name: "导出",
            buttonClass: 'primary',
            width: 100,
            click: ({ row, handlers }) => {   //暴露的方法钩子
                StaffInfoApi.pageDataXls(handlers.getRequestParams(), handlers.getXlsTitle(), exportXlsName.value)
            }
        },
        {
            name: "健康证批量导入",
            buttonClass: 'primary',
            width: 100,
            click: ({ row, handlers }) => {   //暴露的方法钩子
                //  CompanyInfoApi.pageDataXls( handlers.getRequestParams(),handlers.getXlsTitle())
                VDialog.open({
                    title: '健康证批量导入',
                    content: { //内容初始形式
                        type: 'component', //text:"",预留文本
                        name: '/BatchAttachmentUpload',
                        // query: { companyInfoId: row.id },
                    },
                    config: {
                        additionalSaveParams: { type: 1 },
                        templateType: "company_template_type_6",

                    },
                    callBack: (data: any) => {
                        handlers.refresh()
                        console.log("refresh", handlers.refresh)
                        // handlers.refresh()
                        console.log("upload recived data:", data)
                    },
                    onClose: () => {
                        console.log("对话框已关闭");
                    },
                })
            }
        },
        {
            name: "批量删除",
            buttonClass: 'danger',
            width: 100,
            isShow: (row: any) => {
                return false;
            },
            click: () => {   //暴露的方法钩子
                console.log(baseTable.value.getSelection());
            },
        },
    ]
})
// 表格初始化Model
const baseTableModel = ref({
    border: true,
    pagination: true,
    inline: true,
    selectable: true,
    isFullscreen: false,
    tooltip: true,
    minWidth: '200px',
    data: {    //table  初始化
        current: 1,
        size: 10,
        total: 100,
        data: []
    },
    requestData: { api: StaffInfoApi.getPageData, query: {} },   //数据源 参数有效性： 'steady|transient'
    columns: [
        //    {
        //     label: "id",
        //     field: "id",
        //     width:100,
        //       },
        //    {
        //     label: "排序",
        //     field: "sort",
        //     width:120,
        //       },
        {
            label: "人员姓名",
            field: "staffName",
            width: 180,
        },

        {
            label: "性别",
            field: "staffSexName",
            width: 120,
            // render({row}){
            //     return <CommonStatusTag value={row["staffSex"]} valueMap={[
            //         {
            //             value: '0',
            //             lable: "女",
            //             type: "primary"
            //         },
            //         {
            //             value: '1',
            //             lable: "男",
            //             type: "success"
            //         },
            //         {
            //             value: 2,
            //             lable: "未知",
            //             type: "info"
            //         },,
            //     ]} />
            // }
        },

        {
            label: "出生日期",
            field: "staffBirthDate",
            width: 200,
            fieldFormat: "date"
        },
        {
            label: "身份证号",
            field: "staffIdentity",
            width: 180,
        },
        {
            label: "职位",
            field: "staffPosition",
            width: 180,
        },
        {
            label: "入职日期",
            field: "staffEntryDate",
            width: 200,
            fieldFormat: "date"
        },
        {
            label: "健康证号",
            field: "healthCertificateCode",
            width: 220,
        },
        {
            label: "健康证",
            field: "healthCertificateUrl",
            width: 180,
            fieldFormat: 'img'
        },
        {
            label: "健康证有效期",
            field: "healthCertificateDate",
            width: 200,
            fieldFormat: "date"
        },
        //    {
        //     label: "所属公司",
        //     field: "companyId",
        //     width:120,
        //       },
        {
            label: "是否离职",
            field: "status",
            noExported: true,
            width: 120,
            render({ row }) {
                // console.log("row",row)
                // console.log(row["status"],typeof row["status"])
                return <CommonStatusTag value={row["status"]} valueMap={[
                    {
                        value: '0',
                        label: "在职",
                        type: "success"
                    },
                    {
                        value: '1',
                        label: "离职",
                        type: "warning"
                    },
                ]} />
            }
        },
        {
            label: "创建时间",
            field: "create_time",
        },
        {
            label: "更新时间",
            field: "update_time",
        },
    ],


    actions: [
        {
            name: "详情",

            buttonClass: 'primary',
            buttonType: 'text',
            click: ({ row, index, handlers }) => {

                //router.push({name: 'CompanyInfoDetail',})
                VDialog.open({
                    title: '详情',
                    content: { //内容初始形式
                        type: 'component', //text:"",预留文本
                        name: '/staffInfo/detail',
                        query: { staffInfoId: row.id },

                    },
                    callBack: (data: any) => {
                        handlers.refresh()
                    },
                    onClose: () => {
                        console.log("对话框已关闭");
                    },
                });
            },
            isShow: (row: object) => {
                return true;
            },
            fixed: 'right'
        },
        {
            name: "编辑",
            buttonClass: 'primary',   //按钮颜色控制
            buttonType: 'text',      // 按钮风格   text  link  button
            isShow: (row: object) => {  //根据业务做动态隐藏张氏
                return true
            },
            click: ({ row, index, handlers }) => {        // 点击回调事件方法钩子，  点击触发

                VDialog.open({
                    title: '编辑',
                    content: { //内容初始形式
                        type: 'component', //text:"",预留文本
                        name: '/staffInfo/edit',
                        query: { staffInfoId: row.id },

                    },

                    callBack: (data: any) => {
                        handlers.refresh()
                    },
                    onClose: () => {
                        console.log("对话框已关闭");
                    },
                });

            },
            fixed: 'right'
        },

        {
            name: "删除",
            buttonClass: 'danger',
            buttonType: 'text',
            fixed: 'right',
            click: ({ row, index, handlers }) => {
                $baseConfirm('您确定要删除当前项吗', null, async () => {
                    const { message } = await StaffInfoApi.del({ staffInfoIds: row.id })
                    $baseMessage(message, 'success', 'vab-hey-message-success');
                    handlers.refresh()
                })
            }
        },
        // {
        //     name: "下载111",
        //     buttonClass: 'primary',   //按钮颜色控制
        //     buttonType: 'text',      // 按钮风格   text  link  button
        //     isShow: (row: object) => {  //根据业务做动态隐藏张氏
        //         return true
        //     },
        //     click: ({ row, index, handlers }) => {
        //         StaffInfoApi.downloadAttachment(row["healthCertificateUrl"])
        //     },
        //     fixed: 'right'
        // },
        {
            name: "下载",
            buttonClass: 'primary',
            buttonType: 'text',
            isShow: (row: object) => {
                // return true
                return !!row["healthCertificateUrl"]; // 只有当 healthCertificateUrl 存在时才显示下载按钮
            },
            click: ({ row, index, handlers }) => {
                StaffInfoApi.downloadAttachment(row["healthCertificateUrl"])
            },
            fixed: 'right'
        },

    ]

})



onActivated(() => {
})



</script>
